<?php

class Db extends PDO{
	
	private
	$host,
	$user,
	$pass,
	$dbname;
	
	public function __construct($dsn = null, $username = null, $passwd = null, $options = null){
		
		try{
			$this->loadConfig();
			$dsn = 'mysql:host=localhost;dbname='.$this->dbname;
			parent::__construct($dsn, $this->user, $this->pass);
		}
		catch (PDOException $e){
			//gera o log
			echo 'erro';
		}
	}
	
	
	protected function loadConfig(){
		$config = new Config();
		$ini = $config->loadConfig('database');
		
		for($i=0; $i<count($ini); $i++){
			$keys = array_keys($ini);
			if($ini[$keys[$i]]['status'] == 1){
				$arrConfig = $ini[$keys[$i]];
			}
		}
				
		$this->host = $arrConfig['host'];
		$this->user = $arrConfig['user'];
		$this->pass = $arrConfig['pass'];
		$this->dbname = $arrConfig['dbname'];
	}
	
}
